#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File    :   wencai.py
@Time    :   2023/04/06 18:38:44
@Author  :   youle
@Email   :   a_fly0505@163.com
@Copyright : 侵权必究
'''

import argparse
import sys
import requests
import json

url = "http://www.iwencai.com/iwencai/userinfo/iwc/userinfo/self-stock/plate/add"
params = {
}

if __name__ == "__main__":
    argparse = argparse.ArgumentParser()
    argparse.add_argument('-f', help='')
    args = argparse.parse_args()

    # read http header
    with open("params.json", 'r') as f:
        json_data = json.load(f)
        for key in json_data:
            params[key] = json_data[key]

    # read codes    
    jsonCodes: str = ""
    with open(args.f, 'r') as f:
        codeObj = json.load(f)
        for obj in codeObj:
            code = obj['code']
            if code.startswith("60"):
                code = code+'_17'
            elif code.startswith("30") or code.startswith('00'):
                code = code+'_33'
            else:
                print("err:", code)
            jsonCodes = jsonCodes + code + '|'
        jsonCodes = jsonCodes[:-1]
        print("jsonCodes: ", jsonCodes)

    # begin post
    json_body = {
        "sn": "EE",
        "codes": jsonCodes,
        "type": 2
    }
    r = requests.post(url, json=json_body, headers=params)
    print(r.text)
    sys.exit(0)
